<template>
  <div class="task-form">
    <h3>添加新任务</h3>
    <form @submit.prevent="submitForm">
      <div class="form-group">
        <label for="title">任务标题</label>
        <input 
          type="text" 
          id="title" 
          v-model="form.title" 
          required
          placeholder="输入任务标题"
        >
      </div>
      
      <div class="form-group">
        <label for="description">任务描述</label>
        <textarea 
          id="description" 
          v-model="form.description" 
          placeholder="输入任务描述"
        ></textarea>
      </div>
      
      <div class="form-group">
        <label for="dueDate">截止日期</label>
        <input 
          type="date" 
          id="dueDate" 
          v-model="form.dueDate" 
          required
        >
      </div>
      
      <button type="submit" class="submit-button">添加任务</button>
    </form>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const emit = defineEmits(['taskAdded'])

const form = ref({
  title: '',
  description: '',
  dueDate: ''
})

const submitForm = () => {
  if (form.value.title.trim() && form.value.dueDate) {
    emit('taskAdded', {
      title: form.value.title,
      description: form.value.description,
      dueDate: form.value.dueDate
    })
    form.value = {
      title: '',
      description: '',
      dueDate: ''
    }
  }
}
</script>

<style scoped>
.task-form {
  background-color: #fff;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  margin-bottom: 2rem;
}

h3 {
  color: #4a6cf7;
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: bold;
}

input, textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.submit-button {
  padding: 0.75rem 1.5rem;
  background-color: #4a6cf7;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s;
}

.submit-button:hover {
  background-color: #3a5ce7;
}
</style>